package com.example.farmeri.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.farmeri.R;
import com.example.farmeri.data.RetrofitManager;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Retrofit;

/**
 * Create by weiqishan on 2020/4/6.
 * 配置适配器
 */
public class BaseRecycleViewAdapter<T> extends RecyclerView.Adapter{
    public final String TAG = this.getClass().getSimpleName();


    Context context;
    Integer layout;

    List<T> dataList = new ArrayList<>();

    public BaseRecycleViewAdapter(Context context, int layout) {
        this.context = context;
        this.layout = layout;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
        View itemView = inflater.inflate(layout,viewGroup,false);
        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        MyViewHolder myViewHolder = (MyViewHolder) viewHolder;
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }


    private class MyViewHolder extends RecyclerView.ViewHolder {

        HorizontalScrollView container;


        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            container = itemView.findViewById(R.id.item_farm_manager_container);

        }
    }

    protected void showMsg(String msg){
        Toast.makeText(context,msg,Toast.LENGTH_SHORT).show();
    }

    protected void showError(){
        Toast.makeText(context,"网络请求失败",Toast.LENGTH_SHORT).show();
    }

    public Retrofit getRetrofit(){
        return RetrofitManager.getManager().getRetrofit();
    }

    public void cleanData(){
        dataList = new ArrayList<>();
    }
}